import axios from 'axios'
import { ElMessage } from 'element-plus'

// export const baseURL = 'http://121.89.205.189:3000/admin'//基路径

const request = axios.create({
    baseURL: import.meta.env.DEV ? 'http://121.89.205.189:3000/admin' : '生产环境的地址',
    timeout: 6000
})


//请求之前  拦截操作
request.interceptors.request.use((res) => {
    res.headers.token = localStorage.getItem('Token')
    return res
})





//请求之后 响应拦截
request.interceptors.response.use(
    function (res) {
        if (res.data?.code === '200') {
            if (res.config.method !== 'get') ElMessage.success(res.data.message)
        } else if(res.data?.code === '10119'){
            ElMessage.error('登录过期,请重新登录')
        }else{
            ElMessage.error(res.data.message)
        }
        return res.data
    },
)


export default request
